# -*- coding: utf-8 -*-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#作者：cacho_37967865
#博客：https://blog.csdn.net/sinat_37967865
#文件：read_file.py
#日期：2019-11-10
#备注：多种读取文件的方法
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

# readlines()得到list,默认读取所有行（一行一个元素）
def read_lines(file):
    with open(file, "r") as fp:
        info = fp.readlines(1000)          # readlines(n)-->n为字符数量
        #print(type(info))
        print(info)


# readline()得到str，默认读取第一行
def read_line(file):
    with open(file, "r") as fp:
        while True:
            info = fp.readline()
            print(info)


# read()得到str，默认一次性读取文件的全部内容：都到内存里面了，随时取用
def read_all(file):
    with open(file, "r") as fp:
        info = fp.read()           # read(n)-->n为字符数量
        print(info)


if __name__ == '__main__':
    file = 'H:\wei\\file\\江山（校对版全本）作者：沙漠.txt'
    #read_lines(file)
    read_line(file)
    #read_all(file)